<?php
/**
 * @category   Application_Extensions
 * @package    Talktangle Plugin 
 * @copyright  Idragon Co., Ltd.
 * @license
 */
class Talktangle_Widget_CrosstangleController extends Engine_Content_Widget_Abstract {
		
	public function indexAction() {
	   $request = Zend_Controller_Front::getInstance()->getRequest();
       $crossId = $request->getParam('id',0);
       
       if(empty($crossId)){
            return $this->setNoRender();
       }
	   if (!Engine_Api::_()->core()->hasSubject('user')) {
            return $this->setNoRender();
	   }
	   // Get subject
	   $this->view->subject = $viewer = $subject = Engine_Api::_()->core()->getSubject('user');
	
       $coreApi =  Engine_Api::_()->talktangle();
        
       $cross = Engine_Api::_()->getItem('talktangle_crosstangle',$crossId); 
       if(!$cross){
            $this->view->error = true;
            $this->view->message = $this->view->translate('Can not found this tangle, please select other tangle.');
       }
       
       if(!$coreApi->checkTangle($cross)) {
            $this->view->error = true;
            $this->view->message = $this->view->translate('This tangle had been untangle or timeout.');
       }
       
       $tanglecontent = json_decode($cross->content);
       $tanglecontent = get_object_vars($tanglecontent);
       
       $tangledescription = json_decode($cross->description);
       $tangledescription = get_object_vars($tangledescription);
       
       $content = array();
       foreach ($tanglecontent as $key => $value) {
            $content[$key] = trim($value);
       }
       $content = implode(' ',$content);
       
       
       $this->view->matric = $coreApi->crossCharacters($content,$crossId);
       $this->view->anphabetic = $coreApi->anphabetic;	
       $this->view->characters= $characters = $cross->content;
       $this->view->tangleContent = $tanglecontent;
       $this->view->tangleDescription = $tangledescription;
       $this->view->tangle_id = $crossId;
       $this->view->viewer = $viewer;
	}
}